using System.Collections.Generic;
using System.Text;

namespace OracleInternal.SqlAndPlsqlParser.LocalParsing
{
	internal class OracleLpFromListTerm : OracleLpStatementDataContainer
	{
		protected OracleLpFromListTermType m_vType;

		protected OracleLpTableReference m_vTableReference;

		protected List<OracleLpSpecificJoinClause> m_vJoinClauses;

		protected List<OracleLpColumnDescriptor> m_vColumnDescriptors;

		internal override OracleLpStatementElementType ElementType => OracleLpStatementElementType.FromListTerm;

		public OracleLpFromListTermType Type => m_vType;

		public OracleLpTableReference TableReference
		{
			get
			{
				return m_vTableReference;
			}
			set
			{
				m_vTableReference = value;
				if (m_vTableReference != null)
				{
					m_vTableReference.Parent = this;
				}
			}
		}

		public List<OracleLpSpecificJoinClause> JoinClauses => m_vJoinClauses;

		public override List<OracleLpColumnDescriptor> ColumnDescriptors
		{
			get
			{
				if (m_vColumnDescriptors == null)
				{
					Resolve();
				}
				return m_vColumnDescriptors;
			}
		}

		public OracleLpFromListTerm(OracleLpFromListTermType type, OracleLpStatementElement fc)
			: base(fc)
		{
			m_vType = type;
			if (type == OracleLpFromListTermType.JoinClause)
			{
				m_vJoinClauses = new List<OracleLpSpecificJoinClause>();
			}
		}

		public override void Resolve()
		{
			if (m_vType == OracleLpFromListTermType.TableReference)
			{
				m_vColumnDescriptors = m_vTableReference.ColumnDescriptors;
				return;
			}
			m_vColumnDescriptors = new List<OracleLpColumnDescriptor>();
			m_vColumnDescriptors.AddRange(m_vTableReference.ColumnDescriptors);
			foreach (OracleLpSpecificJoinClause vJoinClause in m_vJoinClauses)
			{
				m_vColumnDescriptors.AddRange(vJoinClause.TableReference.ColumnDescriptors);
			}
		}

		public override void RetrieveNamedObjectReferences(OracleLpStatement statement)
		{
			m_vTableReference.RetrieveNamedObjectReferences(statement);
			if (m_vType != OracleLpFromListTermType.JoinClause)
			{
				return;
			}
			foreach (OracleLpSpecificJoinClause vJoinClause in m_vJoinClauses)
			{
				vJoinClause.RetrieveNamedObjectReferences(statement);
			}
		}

		internal override void ToString(StringBuilder sb)
		{
			string depthIndent = base.DepthIndent;
			sb.Append(depthIndent);
			sb.Append("Type: ");
			sb.Append(m_vType);
			sb.Append('\n');
			m_vTableReference.ToString(sb);
			if (m_vType == OracleLpFromListTermType.JoinClause)
			{
				m_vJoinClauses.ForEach(delegate(OracleLpSpecificJoinClause jc)
				{
					jc.ToString(sb);
				});
			}
		}
	}
}
